#include <iostream>
#include <string>
#include <unordered_map>
#include <cmath>

using namespace std;

unordered_map<string, int> wordToNumber = {
    {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
    {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
};

bool isPrime(int n) {
    if (n <= 1) {
        return false;
    }
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0) {
            return false;

      }
    }
    return true;
}
int main() {
    string word1, word2, word3;
    cin >> word1 >> word2 >> word3;

    int number = wordToNumber[word1] * 100 + wordToNumber[word2] * 10 + wordToNumber[word3];

    if (number < 100 || number > 999) {
        cout << "Wrong input" << endl;
    } else {
        int lowerPrime = number;
        int upperPrime = number;
        while (!isPrime(lowerPrime)) {
            lowerPrime--;
        }
        while (!isPrime(upperPrime)) {
            upperPrime++;
        }

        if (number - lowerPrime <= upperPrime - number) {
            cout << lowerPrime << endl;
        } else {
            cout << upperPrime << endl;
        }
    }

    return 0;
}
